VERSION 5.00
Begin VB.Form Status 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Form1"
   ClientHeight    =   2040
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   3735
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2040
   ScaleWidth      =   3735
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  'CenterOwner
   Begin VB.OptionButton Option2 
      Caption         =   "AES"
      Height          =   375
      Left            =   1920
      TabIndex        =   5
      Top             =   840
      Width           =   1455
   End
   Begin VB.OptionButton Option1 
      Caption         =   "TDES"
      Height          =   375
      Left            =   360
      TabIndex        =   4
      Top             =   840
      Width           =   1455
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Cancel"
      Height          =   495
      Left            =   2400
      TabIndex        =   2
      Top             =   1320
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "OK"
      Height          =   495
      Left            =   240
      TabIndex        =   1
      Top             =   1320
      Width           =   1215
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   480
      Width           =   3375
   End
   Begin VB.Label Label2 
      ForeColor       =   &H80000002&
      Height          =   255
      Left            =   360
      TabIndex        =   3
      Top             =   1320
      Width           =   1455
   End
   Begin VB.Label Label1 
      Height          =   1095
      Left            =   360
      TabIndex        =   0
      Top             =   240
      Width           =   3135
   End
End
Attribute VB_Name = "Status"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const IDC_HAND = 32649&
Private Const IDC_ARROW = 32512&
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal _
    hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const clrLinkActive = vbBlue
Private Const clrLinkHot = vbRed
Private Const clrLinkInactive = vbBlack

Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10

Private Type POINTAPI
   X As Long
   Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" _
  (lpPoint As POINTAPI) As Long

Private Declare Function ScreenToClient Lib "user32" _
  (ByVal hwnd As Long, _
   lpPoint As POINTAPI) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function ShellExecute Lib "shell32" _
   Alias "ShellExecuteA" _
  (ByVal hwnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long
   
   
Private Sub Command1_Click()
    InitUSB
    Dim response As Integer
    If MCM.IDvalue = 0 Then
    Sleep (500)
        Const ReadSetting = "52 1F"
        MCM.HIDResult.Text = ""
        If DeviceAttributes.ProductID = ProdID Then
            Call MCM.SendHIDCommand(ReadSetting)
        ElseIf DeviceAttributes.ProductID = ProdID2 Then
            Call MCM.SendHIDKBCommand(ReadSetting)
        ElseIf DeviceAttributes.ProductID = ProdID3 Then
            Call MCM.SendHIDKBCommand(ReadSetting)
        ElseIf DeviceAttributes.ProductID = ProdID4 Then
            Call MCM.SendHIDKBCommand(ReadSetting)
        End If
        'MCM.HIDResult = "06 02 7E 01 31 4C 01 30 4E 09 08 FF FF FF FF FF FF FF FF 23 01 38 77 01 03 10 01 30 11 01 32 12 01 30 13 01 30 14 01 01 15 01 30 16 01 59 17 01 0D 19 01 31 1A 01 31 1B 01 30 1D 01 31 21 01 0D 24 01 30 41 01 35 42 01 30 43 01 30 44 01 30 45 01 30 47 01 11 48 01 13 49 01 04 4A 01 04 4B 01 2A 50 01 30 55 01 30 4D 01 30 60 01 30 61 01 25 62 01 25 63 01 3B 64 01 25 65 01 3B 66 01 25 67 01 21 68 01 3B 69 01 3F 6A 01 3F 6B 01 3F 6C 01 25 6D 01 3B 6E 01 2B 72 01 7F 73 01 7F 7A 01 30 7B 01 30 D2 01 00 D3 0B 0A 31 32 33 34 35 36 37 38 39 30 34 02 01 31 37 03 02 31 32 35 04 03 31 32 33 38 05 04 20 20 20 20 36 06 05 31 32 33 34 35 39 01 00 5C 01 37 86 01 07 84 01 08 85 01 30 5D 01 31 58 01 31 FA 00 FB 00 FC 08 00 FF 00 FF 00 FF 00 FF 03 72 00 00 "
        'MCM.HIDResult = "06 02 7E 01 31 4C 01 30 4E 0B 0A 54 31 31 32 38 30 30 30 38 38 23 01 38 77 01 23 10 01 30 3D 01 00 3E 01 00 85 01 30 11 01 32 12 01 30 13 01 30 14 01 01 15 01 30 16 01 59 17 01 0D 19 01 31 1A 01 31 1B 01 30 1D 01 31 21 01 0D 24 01 30 30 01 00 41 01 35 42 01 30 43 01 30 44 01 30 45 01 30 47 01 11 48 01 13 49 01 04 4A 01 04 4B 01 2A 50 01 30 55 01 30 60 01 30 61 01 25 62 01 25 63 01 3B 64 01 25 65 01 3B 66 01 25 67 01 21 68 01 3B 69 01 3F 6A 01 3F 6B 01 3F 6C 01 25 6D 01 3B 6E 01 2B 6F 01 31 72 01 00 73 01 00 7A 01 30 7B 01 30 D2 01 00 D3 01 00 34 01 00 37 01 00 35 01 00 38 01 00 36 01 00 39 01 00 5C 01 37 86 01 07 84 01 08 5D 01 31 FA 00 FB 00 FC 08 00 FF 00 FF 00 FF 00 FF 03 71 00 00 00"
        If Mid$(MCM.HIDResult, 1, 2) = "06" Then
            If (MCM.parsecmd(MCM.HIDResult)) Then
            'If 1 Then
                MCM.TreeView1.Nodes.Clear
                MCM.ListView1.ListItems.Clear
                MCM.inittree
                MsgBox ("Success!")
        MCM.HIDTimer.Enabled = False
                Me.Hide
            End If
        Else
            MsgBox ("Failed")
        End If
    ElseIf MCM.IDvalue = 1 Then
        Dim CommandOrg, Command As String
        Dim I As Integer
        Dim temp As String
        MCM.setcmdstring
        CommandOrg = MCM.cmdstring '"\52\22" 'txtCommand.Text
        'MsgBox CommandOrg
        'MCM.HIDResult.Text = MCM.cmdstring
        Command = ""
            
        For I = 2 To Len(CommandOrg)
            temp = Mid(CommandOrg, I, 1)
            If temp = Chr(92) Then
                temp = " "
            End If
            Command = Command & temp
        Next I
        
        Call MCM.SendHIDCommand(Command)
        If Mid$(MCM.HIDResult, 1, 3) = "\00" Or Mid$(MCM.HIDResult, 1, 2) = "06" Or Mid$(MCM.HIDResult, 1, 3) = "\15" Then
            Sleep (1000)
            MsgBox ("Success")
            MCM.HIDTimer.Enabled = False
            Me.Hide
        Else
            MsgBox ("Failed" & Mid$(MCM.HIDResult, 1, 2))
        End If
    ElseIf MCM.IDvalue = 3 Then
        If Option1.Value = True Then
            response = MsgBox("If you unit is not encrypted right now, by enable the encryption you will not longer able to revers back to plain text.  Are you sure you want to enable the TDES encryption?", vbYesNo, "Enable TDES")
            If response = 6 Then
                'MsgBox "yes"
                Const enableTDES = "53 4C 01 31"
                If DeviceAttributes.ProductID = ProdID Then
                    Call MCM.SendHIDCommand(enableTDES)
                ElseIf DeviceAttributes.ProductID = ProdID2 Then
                    Call MCM.SendHIDKBCommand(enableTDES)
                ElseIf DeviceAttributes.ProductID = ProdID3 Then
                    MsgBox ("MS246 does not support encryption.")
                ElseIf DeviceAttributes.ProductID = ProdID4 Then
                    MsgBox ("MS246 does not support encryption.")
                End If
            Else
                'MsgBox "no"
            End If
        ElseIf Option2.Value = True Then
            response = MsgBox("If you unit is not encrypted right now, by enable the encryption you will not longer able to revers back to plain text.  Are you sure you want to enable the AES encryption?", vbYesNo, "Enable AES")
            If response = 6 Then
                'MsgBox "yes"
                Const enableAES = "53 4C 01 32"
                If DeviceAttributes.ProductID = ProdID Then
                    Call MCM.SendHIDCommand(enableAES)
                ElseIf DeviceAttributes.ProductID = ProdID2 Then
                    Call MCM.SendHIDKBCommand(enableAES)
                ElseIf DeviceAttributes.ProductID = ProdID3 Then
                    MsgBox ("MS246 does not support encryption.")
                ElseIf DeviceAttributes.ProductID = ProdID4 Then
                    MsgBox ("MS246 does not support encryption.")
                End If
            Else
                'MsgBox "no"
            End If
        Else
            MsgBox "Select a Encryption Type"
        End If
    End If

End Sub

Private Sub Command2_Click()
        'MCM.HIDResult = "06 02 7E 01 31 4C 01 30 4E 09 08 FF FF FF FF FF FF FF FF 23 01 38 77 01 03 10 01 30 11 01 32 12 01 30 13 01 30 14 01 01 15 01 30 16 01 59 17 01 0D 19 01 31 1A 01 31 1B 01 30 1D 01 31 21 01 0D 24 01 30 41 01 35 42 01 30 43 01 30 44 01 30 45 01 30 47 01 11 48 01 13 49 01 04 4A 01 04 4B 01 2A 50 01 30 55 01 30 4D 01 30 60 01 30 61 01 25 62 01 25 63 01 3B 64 01 25 65 01 3B 66 01 25 67 01 21 68 01 3B 69 01 3F 6A 01 3F 6B 01 3F 6C 01 25 6D 01 3B 6E 01 2B 72 01 7F 73 01 7F 7A 01 30 7B 01 30 D2 01 00 D3 01 00 34 01 00 37 01 00 35 01 00 38 01 00 36 01 00 39 01 00 5C 01 37 86 01 07 84 01 08 85 01 30 5D 01 31 58 01 31 FA 00 FB 00 FC 08 00 FF 00 FF 00 FF 00 FF 03 46 00 00 00 FF 00 FF 03 46 00 00 00 FF 00 FF 03 46 00 00 00 FF 00 FF 03 46 00 00 00 "
        'MCM.parsecmd (MCM.HIDResult)
    MCM.HIDTimer.Enabled = False
    Me.Hide
End Sub

Private Sub Form_Activate()
    Label2.Visible = False
    MCM.HIDTimer.Enabled = True
    Label1.Caption = ""
    Label3.Visible = False
    Option1.Visible = False
    Option2.Visible = False
    Command1.Visible = False
    Label1.Alignment = 2
    If Label1.Caption = "Found Unitech USB HID Reader" _
                        Or Label1.Caption = "Found Unitech USB KB Reader" Then
        Command1.Visible = True
    Else
        Command1.Visible = False
    End If
    If MCM.IDvalue = 0 Then
        Status.Caption = "Upload"
        Command1.Caption = "Upload"
        
    ElseIf MCM.IDvalue = 1 Then
        Status.Caption = "Download"
        Command1.Caption = "Download"
        
    ElseIf MCM.IDvalue = 2 Then
        MCM.HIDTimer.Enabled = False
        Label1.Alignment = 0
        Status.Caption = "About"
        Label2.Visible = True
        Command1.Visible = False
        Command2.Caption = "OK"
        Label1.Caption = "MS245/246 Configuration Manage" & vbCrLf & _
                         "Version " & App.Major & "." & App.Minor & "." & App.Revision & vbCrLf & _
                         "Software utility for setting up Unitech MS245 & MS246." & vbCrLf & _
                         "Copyright 2011 Unitech Electronics Co., Ltd."
        Label2.Caption = "http://www.ute.com"
        Label2.FontUnderline = True
        
    ElseIf MCM.IDvalue = 3 Then
        Option1.Visible = True
        Option2.Visible = True
        Label3.Visible = True
        Label3.Caption = "Enable security on MS245." & vbCrLf & "Doesn't apply to MS246."
        Status.Caption = "Security"
        Command1.Caption = "Enable"
        
    End If
End Sub


Private Sub Label1_Change()
    If MCM.IDvalue <> 2 Then
        If Label1.Caption = "Found Unitech USB HID Reader" _
        Or Label1.Caption = "Found Unitech USB KB Reader" Then
            Command1.Visible = True
        Else
            Command1.Visible = False
        End If
    End If
    'Command1.Visible = True '------------------------'
End Sub

Private Sub Label2_Click()
    Call RunShellExecute("open", "http://www.ute.com", "", "", SW_SHOWNORMAL)
End Sub

Private Sub RunShellExecute(sTopic As String, sFile As Variant, _
                            sParams As Variant, sDirectory As Variant, _
                            nShowCmd As Long)

  'execute the passed operation, passing
  'the desktop as the window to receive
  'any error messages
   Call ShellExecute(GetDesktopWindow(), _
                     sTopic, _
                     sFile, _
                     sParams, _
                     sDirectory, _
                     nShowCmd)

End Sub

Private Sub Label2_MouseDown(Button As Integer, Shift As Integer, X As Single, _
    Y As Single)
    SetCursor LoadCursor(0, IDC_HAND)
End Sub

Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, _
    Y As Single)
    SetCursor LoadCursor(0, IDC_HAND)
End Sub
